var _excluded = ['valuePropName', 'options', 'renderDetailItem', 'spaceProps'];
function _extends() {
  _extends = Object.assign
    ? Object.assign.bind()
    : function (target) {
        for (var i = 1; i < arguments.length; i++) {
          var source = arguments[i];
          for (var key in source) {
            if (Object.prototype.hasOwnProperty.call(source, key)) {
              target[key] = source[key];
            }
          }
        }
        return target;
      };
  return _extends.apply(this, arguments);
}
function _objectWithoutProperties(source, excluded) {
  if (source == null) return {};
  var target = _objectWithoutPropertiesLoose(source, excluded);
  var key, i;
  if (Object.getOwnPropertySymbols) {
    var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
    for (i = 0; i < sourceSymbolKeys.length; i++) {
      key = sourceSymbolKeys[i];
      if (excluded.indexOf(key) >= 0) continue;
      if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
      target[key] = source[key];
    }
  }
  return target;
}
function _objectWithoutPropertiesLoose(source, excluded) {
  if (source == null) return {};
  var target = {};
  var sourceKeys = Object.keys(source);
  var key, i;
  for (i = 0; i < sourceKeys.length; i++) {
    key = sourceKeys[i];
    if (excluded.indexOf(key) >= 0) continue;
    target[key] = source[key];
  }
  return target;
}
import { Space } from 'antd';
import 'antd/es/space/style/index.js';
import classnames from 'classnames';
import React, { Fragment } from 'react';
import useRequestOptions from '../../_utils/hooks/useRequestOptions';
import './index.less';
export var defaultRenderDetailItem = function defaultRenderDetailItem(val) {
  if (typeof val === 'boolean') return String(val);
  return val !== undefined ? val : null;
};
/**
 * 文本详情，适用于输入框类、下拉框、单选框、多选框的详情组件
 * @param param0
 * @returns
 */
export default function TextDetail(_ref) {
  var valuePropName = _ref.valuePropName,
    optionsOrRequest = _ref.options,
    _ref$renderDetailItem = _ref.renderDetailItem,
    renderDetailItem =
      _ref$renderDetailItem === void 0 ? defaultRenderDetailItem : _ref$renderDetailItem,
    spaceProps = _ref.spaceProps,
    rest = _objectWithoutProperties(_ref, _excluded);
  var _useRequestOptions = useRequestOptions(optionsOrRequest),
    options = _useRequestOptions.options;
  var value = valuePropName ? rest[valuePropName] : rest.value;
  var vals = Array.isArray(value) ? value : value !== undefined && value !== null ? [value] : [];
  return /*#__PURE__*/ React.createElement(
    Space,
    _extends(
      {
        split: ',',
        wrap: true,
        size: 4,
      },
      spaceProps,
      {
        className: classnames(
          'szzj-field-detail-text',
          spaceProps === null || spaceProps === void 0 ? void 0 : spaceProps.className,
        ),
      },
    ),
    vals.map(function (val) {
      var found =
        options === null || options === void 0
          ? void 0
          : options.find(function (option) {
              return option.value === val;
            });
      return found
        ? /*#__PURE__*/ React.createElement(
            Fragment,
            {
              key: String(val),
            },
            renderDetailItem ? renderDetailItem(found.label) : found.label,
          )
        : /*#__PURE__*/ React.createElement(
            Fragment,
            {
              key: String(val),
            },
            renderDetailItem ? renderDetailItem(val) : val,
          );
    }),
  );
}
